/**
 * 
 */
package co.fitstart.admin.entity.content;

import java.util.Map;

import com.demo2do.core.persistence.support.Filter;
import com.demo2do.core.persistence.support.Order;
import com.demo2do.core.persistence.support.QueryBuilder;

/**
 * @author downpour
 *
 */
public class ArticleModuleSearch implements QueryBuilder {

    private Long moduleId;
    
    private String name;
    
    private Order order;
    
    private Filter filter;

    /**
     * The default constructor
     */
    public ArticleModuleSearch() {
        
        this.order = new Order("serial", "DESC");
        
    }
    
    /* (non-Javadoc)
     * @see com.demo2do.core.persistence.support.QueryBuilder#getPreparedFilter(boolean)
     */
    public Filter getPreparedFilter(boolean refresh) {
        
        if(filter == null || refresh) {
            
            filter = new Filter().addLike("article.name", name)
                                 .addEquals("module.id", moduleId);
        
        }
        
        return filter;
    }

    /* (non-Javadoc)
     * @see com.demo2do.core.persistence.support.QueryBuilder#getOrder()
     */
    public Order getOrder() {
        return this.order;
    }

    /* (non-Javadoc)
     * @see com.demo2do.core.persistence.support.QueryBuilder#buildSentenceTemplate()
     */
    public String buildSentenceTemplate() {
        return "FROM ArticleModule " + getPreparedFilter(false).getWhereSentence() + order.getSentence();
    }

    /* (non-Javadoc)
     * @see com.demo2do.core.persistence.support.QueryBuilder#buildParameters()
     */
    public Map<String, Object> buildParameters() {
        return getPreparedFilter(false).getParameters();
    }

    /**
     * @return the moduleId
     */
    public Long getModuleId() {
        return this.moduleId;
    }

    /**
     * @return the name
     */
    public String getName() {
        return this.name;
    }

    /**
     * @return the filter
     */
    public Filter getFilter() {
        return this.filter;
    }

    /**
     * @param moduleId the moduleId to set
     */
    public void setModuleId(Long moduleId) {
        this.moduleId = moduleId;
    }

    /**
     * @param name the name to set
     */
    public void setName(String name) {
        this.name = name;
    }

}
